import 'package:flutter_app/http/HttpDIo.dart';
import 'package:fluttertoast/fluttertoast.dart';

class DioRepository {
  HttpDio _httpDio;

  DioRepository() {
    _httpDio = HttpDio.getInstance();
  }

  getUri(String uri, {Function(dynamic json) onSuccess}) {
    _httpDio.getUri(uri, onNext: (rep) {
      onSuccess(rep);
    }, onFail: (code, msg) {
      Fluttertoast.showToast(msg: msg);
    },onComplete: (){});
  }

  ///<p>搜索小说</p>
  ///<p>[option] 搜索类型</p>
  ///<p>[key] 关键字</p>
  ///<p>[page] 页数</p>
  ///<p>[size] 数量</p>
  searchFiction(String option, String key, int page, int size,
      {Function(dynamic json) onSuccess}) {
    getUri("fiction/search/$option/$key/$page/$size", onSuccess: (rep) {
      onSuccess(rep);
    });
  }

  ///查询章节
  ///<p>[fictionId] 小说id</p>
  getFictionChapters(String fictionId, {Function(dynamic json) onSuccess}) {
    getUri("fictionChapter/search/$fictionId", onSuccess: (rep) {
      onSuccess(rep);
    });
  }

  ///查询章节内容
  getFictionContent(String chapterId, {Function(dynamic json) onSuccess}) {
    getUri("fictionContent/search/$chapterId", onSuccess: (rep) {
      onSuccess(rep);
    });
  }


  ///<p>搜索漫画</p>
  ///<p>[option] 搜索类型</p>
  ///<p>[key] 关键字</p>
  ///<p>[page] 页数</p>
  ///<p>[size] 数量</p>
  searchComics(String option, String key, int page, int size,
      {Function(dynamic json) onSuccess}) {
    getUri("cartoon/search/$option/$key/$page/$size", onSuccess: (rep) {
      onSuccess(rep);
    });
  }


  ///查询漫画章节
  ///<p>[fictionId] 漫画id</p>
  getComicsChapters(String cartoonId, {Function(dynamic json) onSuccess}) {
    getUri("cartoonChapter/search/$cartoonId", onSuccess: (rep) {
      onSuccess(rep);
    });
  }

  ///查询漫画章节内容
  ///<p>[fictionId] 漫画id</p>
  getComicsContent(String chapterId, {Function(dynamic json) onSuccess}) {
    getUri("cartoonContent/search/$chapterId", onSuccess: (rep) {
      onSuccess(rep);
    });
  }

}
